using System;

namespace ExcelProcessor
{
    public abstract class BaseExcelRow
    {
        public int Id { get; set; }  // 行号
        public string Property1 { get; set; }  // A列
        public string Property2 { get; set; }  // B列
        public string Property3 { get; set; }  // C列
        public string Property4 { get; set; }  // D列
        public string Property5 { get; set; }  // E列

        // 公共方法
        public double SumProperty(int start, int end, double[] values)
        {
            if (start < 0 || end >= values.Length || start > end)
                throw new ArgumentException("Invalid range");

            double sum = 0;
            for (int i = start; i <= end; i++)
            {
                sum += values[i];
            }
            return sum;
        }

        // 抽象属性
        public abstract double[] NumericProperties { get; }
        public abstract string Property7 { get; set; }
        public abstract string Property8 { get; set; }
        public abstract string Property9 { get; set; }
    }
}

namespace ExcelProcessor
{
    public class ExcelRow : BaseExcelRow
    {
        public override double[] NumericProperties { get; } = new double[12];  // G-R列
        public override string Property7 { get; set; }  // AD列
        public override string Property8 { get; set; }  // AE列
        public override string Property9 { get; set; }  // AF列
    }
}

namespace ExcelProcessor
{
    public class Summary : BaseExcelRow
    {
        public override double[] NumericProperties { get; } = new double[12];  // F-Q列
        public override string Property7 { get; set; }  // U列
        public override string Property8 { get; set; }  // V列
        public override string Property9 { get; set; }  // W列
    }
}

using NPOI.SS.UserModel;
using System.Collections.Generic;
using System.IO;

namespace ExcelProcessor
{
    public class ExcelReader<T> where T : BaseExcelRow, new()
    {
        private readonly int _numericStartCol;
        private readonly int _prop7Col;
        private readonly int _prop8Col;
        private readonly int _prop9Col;

        public ExcelReader(int numericStart, int prop7, int prop8, int prop9)
        {
            _numericStartCol = numericStart;
            _prop7Col = prop7;
            _prop8Col = prop8;
            _prop9Col = prop9;
        }

        public List<T> ReadExcel(string filePath)
        {
            var rows = new List<T>();

            using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                var workbook = WorkbookFactory.Create(fs);
                var sheet = workbook.GetSheetAt(0);

                for (int rowNum = 1; rowNum <= sheet.LastRowNum; rowNum++)
                {
                    var row = sheet.GetRow(rowNum);
                    if (row == null) continue;

                    var item = new T
                    {
                        Id = rowNum,
                        Property1 = GetCellString(row, 0),
                        Property2 = GetCellString(row, 1),
                        Property3 = GetCellString(row, 2),
                        Property4 = GetCellString(row, 3),
                        Property5 = GetCellString(row, 4)
                    };

                    // 读取数值列
                    for (int i = 0; i < item.NumericProperties.Length; i++)
                    {
                        item.NumericProperties[i] = GetCellDouble(row, _numericStartCol + i);
                    }

                    // 读取其他属性
                    item.Property7 = GetCellString(row, _prop7Col);
                    item.Property8 = GetCellString(row, _prop8Col);
                    item.Property9 = GetCellString(row, _prop9Col);

                    rows.Add(item);
                }
            }

            return rows;
        }

        private static string GetCellString(IRow row, int column)
            => row.GetCell(column)?.ToString() ?? string.Empty;

        private static double GetCellDouble(IRow row, int column)
            => double.TryParse(row.GetCell(column)?.ToString(), out var result) ? result : 0;
    }
}
// 使用示例
// 读取原始数据
var rowReader = new ExcelReader<ExcelRow>(
    numericStart: 6,  // G列开始
    prop7: 29,        // AD列
    prop8: 30,        // AE列
    prop9: 31         // AF列
);
var rows = rowReader.ReadExcel("data.xlsx");

// 读取汇总数据
var summaryReader = new ExcelReader<Summary>(
    numericStart: 5,  // F列开始
    prop7: 20,        // U列
    prop8: 21,        // V列
    prop9: 22         // W列
);
var summaries = summaryReader.ReadExcel("summary.xlsx");

// 使用求和功能
var rowSum = rows[0].SumProperty(0, 5, rows[0].NumericProperties);
var summarySum = summaries[0].SumProperty(3, 8, summaries[0].NumericProperties);